Template.channel_chatroom_list_item.onRendered(function () {
  let itemSum = Session.get('class.channelChatroom.renderedItemSum');
  ++itemSum;

  Session.set('class.channelChatroom.renderedItemSum', itemSum);
});

Template.channel_chatroom_list_item.helpers({
  isCurrent: function () {
    return Template.instance().data.result.userId === Meteor.userId();
  },

  username: function () {
    return Template.instance().data.result.user.username;
  },

  avatar: function () {
    return Template.instance().data.result.user.profile.avatar;
  },

  text: function () {
    return Template.instance().data.result.details.text;
  },

  time: function () {
    return Template.instance().data.result.createdAt
  },

  showTime: function() {
    return Template.instance().data.result.showTime;
  },
});

Template.channel_chatroom_list_item.events({
  'click .delete-channel-chatroom-message' (e, instance) {
    Session.set('class.deleteModal.title', '确定删除这条信息？删除之后不可恢复。');
    Session.set('class.deleteModal.type', 'delete-channel-message');
    Session.set('class.deleteModal.id', instance.data.result._id);
    $('#delete-modal').modal();
  },

  'click .go-homepage' (e, instance) {
    e.preventDefault();
    Router.go(`/u/${instance.data.result.user.username}`);
  }
});